package com.xintai.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.system.domain.PubCoderule;
import com.xintai.system.service.IPubCoderuleService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 单据编号规则Controller
 * 
 * @author xintai
 * @date 2021-01-09
 */
@RestController
@RequestMapping("/system/coderule")
public class PubCoderuleController extends BaseController
{
    @Autowired
    private IPubCoderuleService pubCoderuleService;

    /**
     * 查询单据编号规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:coderule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PubCoderule pubCoderule)
    {
        startPage();
        List<PubCoderule> list = pubCoderuleService.selectPubCoderuleList(pubCoderule);
        return getDataTable(list);
    }

    /**
     * 导出单据编号规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:coderule:export')")
    @Log(title = "单据编号规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PubCoderule pubCoderule)
    {
        List<PubCoderule> list = pubCoderuleService.selectPubCoderuleList(pubCoderule);
        ExcelUtil<PubCoderule> util = new ExcelUtil<PubCoderule>(PubCoderule.class);
        return util.exportExcel(list, "coderule");
    }

    /**
     * 获取单据编号规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:coderule:query')")
    @GetMapping(value = "/{crId}")
    public AjaxResult getInfo(@PathVariable("crId") Long crId)
    {
        return AjaxResult.success(pubCoderuleService.selectPubCoderuleById(crId));
    }

    /**
     * 新增单据编号规则
     */
    @PreAuthorize("@ss.hasPermi('system:coderule:add')")
    @Log(title = "单据编号规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PubCoderule pubCoderule)
    {
        return toAjax(pubCoderuleService.insertPubCoderule(pubCoderule));
    }

    /**
     * 修改单据编号规则
     */
    @PreAuthorize("@ss.hasPermi('system:coderule:edit')")
    @Log(title = "单据编号规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PubCoderule pubCoderule)
    {
        return toAjax(pubCoderuleService.updatePubCoderule(pubCoderule));
    }

    /**
     * 删除单据编号规则
     */
    @PreAuthorize("@ss.hasPermi('system:coderule:remove')")
    @Log(title = "单据编号规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{crIds}")
    public AjaxResult remove(@PathVariable Long[] crIds)
    {
        return toAjax(pubCoderuleService.deletePubCoderuleByIds(crIds));
    }
}
